/*
 * Copyright 2010 The MIauto Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef SERVO_H_
#define SERVO_H_

#include <avr/pgmspace.h>
#include <stdint.h>
#include <avr/sfr_defs.h>

#define DEFAULT_VELOCITY 1020
#define VELOCITY_MULTIPLYER 5
#define DEFAULT_DIRECTION 0
#define DIRECTION_MULTIPLYER 1
#define T_SERVO_STRUCT_SIZE 11

#define SERVO_COUNT 2
#define DIRECTION_SERVO 0
#define THROTLE_SERVO 1

typedef struct
{
	uint8_t u8Multiplyer;
	uint16_t u16DefaultDirection;
	uint16_t u16MaxDirection;
	uint16_t u16MinDirection;
	uint16_t u16Direction;
	volatile uint16_t *ocr;
	void* pMemAdd;
} t_Servo;

extern volatile t_Servo servos[SERVO_COUNT];

void PWM_Init(void);
void stopServos(void);
void setDirect(volatile t_Servo *tServo, uint8_t u8Dir);
void stopServo(volatile t_Servo *tServo);
void saveServoSettings(volatile t_Servo *tServo);
void setServoSettings(volatile t_Servo *tServo, uint8_t u8Mul,
		uint16_t u16DefDir, uint16_t u16MaxDir, uint16_t u16MinDir,
		uint16_t u16Dir, volatile uint16_t *pu8ocr);

#endif /* SERVO_H_ */
